<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 会员促销
 * @package  htdocs
 * @subpackage  quanliadmin
 * @create by allen.qiang
 */


class pa_promotionCustomer {

    public function execute() {
        global $G_PGLOB ;
        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //会员促销列表
                    $this->promotionCustomerList();
                    break;

                case 100: //添加会员促销
                    $this->promotionCustomerAdd();
                    break;

                case 101: //编辑会员促销
                    $this->promotionCustomerEdit();
                    break;

                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
                    $G_PGLOB->smarty->display('comm/error.tpl');

            }
        }
    }

    /**
     * 会员促销列表
     *
     */
    private function promotionCustomerList() {

        global $G_PGLOB;

        $G_PGLOB->smarty->assign('edit_permission', $G_PGLOB->has_permission(4517));

        $G_PGLOB->smarty->display('promotion/promotionCustomerList.tpl');

    }

    /**
     * 添加会员促销
     */
    private function promotionCustomerAdd () {

        global $G_PGLOB;

        //帐户礼品券
        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime) ;

        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);
        $G_PGLOB->smarty->assign('operFlg', 2);
        $G_PGLOB->smarty->display('promotion/promotionCustomerAdd.tpl');

    }

    /**
     * 编辑会员促销
     */
    public function promotionCustomerEdit() {

        global $G_PGLOB;

        if (!isset($_REQUEST['promotionID']) || !is_numeric($_REQUEST['promotionID'])) {
            $G_PGLOB->smarty->assign('msg', '参数错误');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;

        }

        //查询会员促销信息
        $promotion_customer_obj = new entity('promotion_customer');
        $promotion_customer_obj->promotionID = $_REQUEST['promotionID'];

        if( !$G_PGLOB->DBCA->fetch($promotion_customer_obj) ){
            $G_PGLOB->smarty->assign('msg', '没有找到会员促销信息');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
        }

        //帐户礼品券
        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime);

        //记录会员促销赠送的优惠券信息
        $promotion_customer_coupon_info = '';

        if( $promotion_customer_obj->type == 2 ){

            //查询会员促销赠送优惠券信息
            $search_promotion_customer_coupon_info = 'SELECT * FROM promotion_customer_coupon WHERE promotionID = ?';
            $promotion_customer_coupon_info        = $G_PGLOB->DBCA->stmt_query($search_promotion_customer_coupon_info,'i',$_REQUEST['promotionID']);

            if( empty($promotion_customer_coupon_info) ){
                $G_PGLOB->smarty->assign('msg', '没有找到会员促销赠送的优惠券信息');
                $G_PGLOB->smarty->display('comm/error.tpl');
                die() ;
            }

        }

        $G_PGLOB->smarty->assign('CustomerCouponInfo' , $promotion_customer_coupon_info);
        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);
        $G_PGLOB->smarty->assign('promotion_customer' , $promotion_customer_obj);
        $G_PGLOB->smarty->assign('operFlg', 3);
        $G_PGLOB->smarty->display('promotion/promotionCustomerAdd.tpl');

    }

}